import { Options } from '@vitejs/plugin-vue-jsx';
import type { FormRule, PrimaryTableCol, SelectProps } from 'tdesign-vue-next';
import { Row, Tag } from 'tdesign-vue-next';
import { h } from 'vue';

import { t } from '@/locales';

/**
 * 搜索表单项
 */
export const searchParams: SearchParamsProps[] = [
    {
        label: t('pages.sysRole.name'),
        key: 'name',
    },
    {
        label: t('pages.sysRole.code'),
        key: 'code',
    },
];

/**
 * 表格列
 */
export const columns: PrimaryTableCol[] = [
    {
        colKey: 'row-select',
        type: 'multiple',
        width: 50,
    },
    {
        title: t('pages.sysRole.name'),
        ellipsis: true,
        align: 'center',
        colKey: 'name',
    },
    {
        title: t('pages.sysRole.code'),
        ellipsis: true,
        align: 'center',
        colKey: 'code',
    },
    {
        title: t('pages.sysRole.status'),
        ellipsis: true,
        align: 'center',
        colKey: 'status',
        cell: (h, { row }) =>
            h(
                Tag,
                { theme: row.status == 0 ? 'primary' : 'danger' },
                t(`components.isSetup.${row.status == 0 ? 'on' : 'off'}`),
            ),
    },
    {
        title: t('pages.sysRole.remarks'),
        ellipsis: true,
        align: 'center',
        colKey: 'remarks',
    },
];

/**
 * 表单校验规则
 */
export const rules: Record<string, FormRule[]> = {
    name: [{ required: true, message: t('pages.sysRole.required.name'), type: 'error', trigger: 'blur' }],
    code: [{ required: true, message: t('pages.sysRole.required.code'), type: 'error', trigger: 'blur' }],
};

/**
 * 状态下拉框可选的数据
 */
export const statusOptions: SelectProps['options'] = [
    {
        label: t(`components.isSetup.on`),
        value: 0,
    },
    {
        label: t(`components.isSetup.off`),
        value: 1,
    },
];
